#!/usr/bin/env ksh

#=========================================================================
## Template code
Version=V1
ShellName="$(echo $0|awk -F / '{print $NF}')";ShellOption="$@";
WorkDir="$(echo $0|sed s/${ShellName}//g)";[ -z "${WorkDir}" ] && WorkDir=${PWD};cd ${WorkDir};WorkDir=${PWD}
RoshUser="root";LogLevel=3;HostName=$(uname -n);typeset uname_a=$(uname -a);Platform=$(echo ${uname_a%% *}|tr a-z A-Z);
##import template
for inopt in ${ShellOption}
do
  case $(echo $inopt|tr a-z A-Z) in
  -AGAIN) CurOpt="-AGAIN";continue;;
  esac
  case "${CurOpt}" in
  -AGAIN) typeset PShellName="${inopt}";typeset CurOpt="";continue;;
  esac
done
LogDir="${WorkDir}/logs";mkdir -p ${LogDir};chmod -R ugo+rwx ${LogDir} 2>/dev/null
LogFile="${LogDir}/${PShellName:-${ShellName}}.log"
f_PrintLog "Debug" "Check common function" 2>/dev/null
if [ $? -ne 0 -a "${CurOpt}" != "AGAIN" ]
then
  cat ${WorkDir}/../lib/Common.func$Version ${WorkDir}/${ShellName} >${WorkDir}/.${ShellName}_$$ || exit 1
  sh ${WorkDir}/.${ShellName}_$$ -AGAIN "${ShellName}" "${ShellOption}";
  typeset _rtCode=$?
  rm ${WorkDir}/.${ShellName}_$$
  exit ${_rtCode:-5}
fi
#-------------------------------------------------------------------------
f_SATemplate;f_CheckShellCount;
LogDir="${WorkDir}/logs";mkdir -p ${LogDir};chmod -R 777 ${LogDir} 2>/dev/null
LogFile="${LogDir}/${PShellName:-${ShellName}}.his.${HostName}.0"
hostname 1>/dev/null 2>&1||syntax;
HostName=$(hostname);HostIP=$(grep ${HostName} /etc/hosts|awk '{print $1}'|grep -v "#"|head -1)
UserID=$(id -u);UserName=$(whoami);
#typeset UserHome=$(awk -F: -v un="${UserName}" '{if($1==un){print $6;exit}}' /etc/passwd 2>/dev/null)
#=========================================================================
## User code
#-------------------------------------------------------------------------
function f_ora_query_db_unique_name
{
typeset SAJson=$(curl --silent --connect-timeout 2 \
             http://99.12.230.103/ngap/api/custom/datasource/execute_with_json?id=2102&${_params})

if [$SAJson]; then

fi
}

for inopt in $@
do
  case $(echo $inopt|tr a-z A-Z) in
  -DBHOST) CurOpt="-DBHOST";continue;;
  -DBINST) CurOpt="-DBINST";continue;;
  -DATABASEVIP) CurOpt="-DATABASEVIP";continue;;
  -SERVICENAME) CurOpt="-SERVICENAME";continue;;
  esac
  case "${CurOpt}" in
  -DBHOST) typeset DBHost="${inopt}";continue;;
  -DBINST) typeset DBInst="${inopt}";continue;;
  -DATABASEVIP) typeset DatabaseVip="${DatabaseVip} ${inopt}";;
  -SERVICENAME) typeset ServiceName="${inopt}";continue;;
  esac
done

[ -z "${DBInst}" ] && f_PrintLog "Error" "instance name must not null."
typeset check_instance_exist=`ps -ef|grep ora_pmon_${DBInst}|grep -v grep|wc -l`
if [ ${check_instance_exist} -eq 0 ]; then
  f_PrintLog "Error" "Instance ${DBInst} is not existing on host ${DBHost}"
fi
if [ "${Platform}" = "LINUX" ]; then
  source ~oracle/.bash_profile
else
  . ~oracle/.profile
fi
export ORACLE_SID=${DBInst}
f_ora_query_db_unique_name